package com.atguigu.mr.flow;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @description:
 * @create: 2019-12-15 22:15
 * @author: baojinlong
 **/
public class FlowCountMapper extends Mapper<LongWritable, Text, Text, FlowBean> {
    /**
     * 当前key
     */
    private Text nowKey = new Text();
    /**
     * 当前value
     */
    private FlowBean nowValue = new FlowBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 原始数据 18867144238 120.1.178.22 11115 889 200
        // 1.读取一行数据
        String line = value.toString();
        // 2.切割18715408778
        String[] fields = line.split("\t");
        // 3.封装对象手机号
        nowKey.set(fields[1]);
        int length = fields.length;
        nowValue.setUpFlow(Long.parseLong(fields[length - 3]));
        nowValue.setDownFlow(Long.parseLong(fields[length - 2]));
        // 4.写出数据
        context.write(nowKey, nowValue);
    }
}
